const axiosDownloadUtils = new class AxiosDownloadUtils {
    download(blob, filename = 'unknown') {
        // 创建隐藏的可下载链接
        const eleLink = document.createElement('a');
        eleLink.download = filename;
        eleLink.style.display = 'none';
        // 为 link 赋值
        eleLink.href = URL.createObjectURL(blob);
        // 触发点击
        document.body.appendChild(eleLink);
        eleLink.click();
        // 然后移除
        document.body.removeChild(eleLink);
    }

    /**
     * post请求下载文件
     * @param url
     * @param fileName
     * @param data
     * @returns {Promise<void>}
     */
    async postDownloadUrl(url, fileName, data) {
        const res = await axios({
            method: 'post',
            url: url,
            data: data,
            responseType: 'blob',
        });
        this.download(res.data, fileName);
    }

    /**
     * get请求下载文件
     * @param url
     * @param fileName
     * @param data
     * @returns {Promise<void>}
     */
    async MethodGetDownloadUrl(url, fileName, data) {
        const res = await axios({
            method: 'get',
            url: url,
            data: data,
            responseType: 'blob',
        });
        this.download(res.data, fileName);
    }

}()